package org.example.edusmart.controller.Public;

import com.alibaba.dashscope.aigc.generation.GenerationResult;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import org.example.edusmart.request.Public.ChatPojo;
import org.example.edusmart.service.ChatService;
import org.example.edusmart.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/ai")
public class ChatController {

    @Autowired
    private ChatService chatService;

    @PostMapping("/chat/")
    @PreAuthorize("hasAuthority('public_permission')")
    public Result chatAi(@RequestBody ChatPojo chatPojo) throws NoApiKeyException, InputRequiredException {
        GenerationResult generationResult = chatService.chatAi(chatPojo);

        return new Result(generationResult,200,"成功");
    }
}